//
//  DEOViewController.m
//  demo
//
//  Created by sam on 04/23/2021.
//  Copyright (c) 2021 sam. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
@interface SEGDdManager : NSObject
-(void)requestQueryCommunityListV2WithCommunityName:(NSString*)communityName code:(NSString*)code finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished;


/// 微信一键登陆
/// @discussion /uhomecp-sso/v1/fast/login/wxCodeToLogin
/// @param jsCode 微信授权code
-(void)requestWxCodeToLoginWithJsCode:(NSString*)jsCode finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished;

/// 快速注册并自动登录
/// @discussion /uhomecp-sso/v1/fast/login/fastRegister
/// @param tel 加密密文
/// @param communityId 项目ID
/// @param openId 微信openId（如果是微信绑定后快速注册必传）
/// @param iosUserId 苹果userId（如果是苹果绑定后快速注册必传）
-(void)requestFastRegisterWithTel:(NSString*)tel communityId:(NSString*)communityId openId:(NSString*)openId iosUserId:(NSString*)iosUserId finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished;

/// 手机号一键登录
/// @discussion /uhomecp-sso/v1/fast/login/loginByTel
/// @param tel 加密密文（不带区号）
-(void)requestLoginByTelWithTel:(NSString*)tel finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished;

/// 根据极光token获取用户信息
/// @discussion /uhomecp-sso/v1/fast/login/getTelByJgToken
/// @param jgToken 极光token
-(void)requestGetTelByJgTokenWithJgToken:(NSString*)jgToken finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished;

/// 检验短信并自动登录
/// @discussion /uhomecp-sso/v1/fast/login/validSms
/// @param smsCode 短信验证码
/// @param businessCode 短信业务编码（三一同注册一样）
/// @param tel 手机号
-(void)requestValidSmsWithSmsCode:(NSString*)smsCode businessCode:(NSString*)businessCode tel:(NSString*)tel finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished;

/// 绑定微信
/// @discussion /uhomecp-sso/v1/fast/login/wxBind
/// @param openId 微信openId
/// @param tel 手机号
-(void)requestWxBindWithOpenId:(NSString*)openId tel:(NSString*)tel finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished;

/// 绑定苹果
/// @discussion /uhomecp-sso/v1/fast/login/iosBind
/// @param iosUserId 苹果userId
/// @param tel 手机号
-(void)requestIosBindWithIosUserId:(NSString*)iosUserId tel:(NSString*)tel finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished;

/// 苹果一键登陆
/// @discussion /uhomecp-sso/v1/fast/login/iosCodeToLogin
/// @param iosUserId 微信授权code
-(void)requestIosCodeToLoginWithIosUserId:(NSString*)iosUserId finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished;

/// 获取默认小区
/// @discussion /uhomecp-sso/v2/community/getDefaultCommunity
-(void)requestGetDefaultCommunityWithFinished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished;

/// 选择小区
/// @discussion /uhomecp-sso/v1/userAppCrLand/queryCommunityListV2
/// @param communityName communityName或code必传其一
/// @param code communityName或code必传其一
-(void)requestQueryCommunityListV2WithCommunityName:(NSString*)communityName code:(NSString*)code finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished;

@end
@implementation SEGDdManager
-(void)requestQueryCommunityListV2WithCommunityName:(NSString*)communityName code:(NSString*)code finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished {
}
@end
NS_ASSUME_NONNULL_END

#import <ReactiveObjC/ReactiveObjC.h>
#import "DEOViewController.h"

@interface DEOViewController ()
@property (nonatomic, strong) RACCommand *requestCommand;

@property (nonatomic, strong) SEGDdManager *ddManager;
@property (nonatomic, strong) RACCommand *queryCommunityListV2Command;
@end

@implementation DEOViewController


-(void)seg_requestCommand{
    //@weakify(self);
    _requestCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            //@strongify(self);
            
            // Code here...
            // [subscriber sendNext:nil];
            // [subscriber sendCompleted];
            
            // NSError *error = [NSError errorWithDomain:@"" code:0 userInfo:@{NSLocalizedDescriptionKey:@"error!"}]
            // [subscriber sendError:error];
            return [RACDisposable disposableWithBlock:^{
            }];
        }];
    }];
    
    [self seg_queryCommunityListV2Command];
}

#pragma mark - Network
/// 选择小区
-(void)seg_queryCommunityListV2Command {
    _queryCommunityListV2Command = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            //@strongify(self);
            
            // Code here...
            [self.ddManager requestQueryCommunityListV2WithCommunityName:@"" code:@"" finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
                
                if (!isSuccessed) {
                    NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:errorMessage}];
                    [subscriber sendError:error];
                    return;
                }
                
                [subscriber sendNext:nil];
                [subscriber sendCompleted];
            }];
            
            return [RACDisposable disposableWithBlock:^{
            }];
        }];
    }];
}

-(SEGDdManager *)ddManager {
    if (!_ddManager) {
        _ddManager = [[SEGDdManager alloc] init];
    }
    return _ddManager;
}
@end
